﻿using System.Windows;
using System.Windows.Controls;
using compshop.Modules.DepartmentList.Presenter;
using compshop.Infrastructure.CompShopDataService;


namespace compshop.Modules.DepartmentList.View
{
    /// <summary>
    /// Логика взаимодействия для ClientOrderListView.xaml
    /// </summary>
    public partial class DepartmentListView : UserControl, IViewDepartmentList
    {
        public DepartmentListPresenter Presenter { get; set; }

        public DepartmentListView()
        {
            InitializeComponent();
        }

        public DepartmentListView(DepartmentListPresenter prsnt)
            : this()
        {
            Presenter = prsnt;
            Presenter.View = this;
            DataContext = prsnt;
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            if (lvDepartmentList.SelectedValue != null)
                Presenter.ShowDepartmentDialog(lvDepartmentList.SelectedValue as Department);
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            Presenter.ShowDepartmentDialog(null);
        }

        private void lvDepartmentList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Department selected = (sender as ListView).SelectedValue as Department;
            if (selected != null)
                Presenter.onSelectedDepartment((int)selected.DepartmentID);
        }
        
        public void UpdateData()
        {
            lvDepartmentList.ItemsSource = null;
            lvDepartmentList.ItemsSource = Presenter.Departments;
            lvDepartmentList.UpdateLayout();
        }

        public void ShowData()
        {
        }        
    }
}
